/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * pantallaCita.java
 *
 * Created on 01-may-2011, 19:39:57
 */

package interfaces.farmacia;

import Controlador.Controlador;
import Definiciones.Definiciones;
import GestorFarmacia.Medicamento;
import clinica.ClinicaView;
import clinica.Interfaces;
import java.io.IOException;
import java.security.NoSuchAlgorithmException;
import java.sql.SQLException;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.Arrays;
import javax.swing.JTable;
import javax.swing.ListSelectionModel;
import javax.swing.table.DefaultTableModel;
import org.jdesktop.application.Action;

/**
 *
 * @author eslogan
 */
public class seleccionarMedicamento extends javax.swing.JPanel {
    private ClinicaView app;
    private Interfaces _anterior;
    private ArrayList<Medicamento> _l_medicamentos = new ArrayList<Medicamento>();

    /** Creates new form altaUsuario */
    public seleccionarMedicamento(ClinicaView a) {
        initComponents();
        app = a;
        categoria_a.setRowHeight(32);
        categoria_a.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
        categoria_b.setRowHeight(32);
        categoria_b.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
        categoria_c.setRowHeight(32);
        categoria_c.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
        categoria_d.setRowHeight(32);
        categoria_d.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
        categoria_g.setRowHeight(32);
        categoria_g.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
        categoria_h.setRowHeight(32);
        categoria_h.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
        categoria_j.setRowHeight(32);
        categoria_j.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
        categoria_l.setRowHeight(32);
        categoria_l.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
        categoria_m.setRowHeight(32);
        categoria_m.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
        categoria_n.setRowHeight(32);
        categoria_n.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
        categoria_p.setRowHeight(32);
        categoria_p.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
        categoria_r.setRowHeight(32);
        categoria_r.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
        categoria_s.setRowHeight(32);
        categoria_s.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
        categoria_v.setRowHeight(32);
        categoria_v.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    }

    public void rellenarMedicamentos(Interfaces ant) throws SQLException, IOException, ClassNotFoundException {
        _anterior = ant;
        _l_medicamentos.clear();
        rellenaTabla(Definiciones.ATC.A,categoria_a);
        rellenaTabla(Definiciones.ATC.B,categoria_b);
        rellenaTabla(Definiciones.ATC.C,categoria_c);
        rellenaTabla(Definiciones.ATC.D,categoria_d);
        rellenaTabla(Definiciones.ATC.G,categoria_g);
        rellenaTabla(Definiciones.ATC.H,categoria_h);
        rellenaTabla(Definiciones.ATC.J,categoria_j);
        rellenaTabla(Definiciones.ATC.L,categoria_l);
        rellenaTabla(Definiciones.ATC.M,categoria_m);
        rellenaTabla(Definiciones.ATC.N,categoria_n);
        rellenaTabla(Definiciones.ATC.P,categoria_p);
        rellenaTabla(Definiciones.ATC.R,categoria_r);
        rellenaTabla(Definiciones.ATC.S,categoria_s);
        rellenaTabla(Definiciones.ATC.V,categoria_v);
    }
    
    private void rellenaTabla(Definiciones.ATC atc, JTable categoria) throws SQLException, IOException, ClassNotFoundException {
        ArrayList<Medicamento> l_medicamentos_categoria = new ArrayList<Medicamento>();
        if(_l_medicamentos.size() <= 0) _l_medicamentos.addAll(Arrays.asList(Controlador.buscarMedicamento(null, null, null, null, null, null, null, null, null)));
        limpiarTabla(categoria);
        for(Medicamento med:_l_medicamentos)
            if(med.getCategoriaMedicamento() == atc) l_medicamentos_categoria.add(med);
        if(l_medicamentos_categoria.size() > 0){
            for(Medicamento med:l_medicamentos_categoria) {
                String [] valores = {""+med.getNombreMedicamento(),""+med.getDCI(),""+med.getViaAdministracion()};
                ((DefaultTableModel)categoria.getModel()).addRow(valores);
            }
        }
    }
    
    private Medicamento objetoFila(int panel_activo) throws SQLException, IOException, ClassNotFoundException {
        Definiciones.ATC atc = null;
        JTable categoria = null;
        ArrayList<Medicamento> l_medicamentos_categoria = new ArrayList<Medicamento>();

        if(panel_activo == 0)       { atc =  Definiciones.ATC.A; categoria = categoria_a; }
        else if(panel_activo == 1)  { atc =  Definiciones.ATC.B; categoria = categoria_b; }
        else if(panel_activo == 2)  { atc =  Definiciones.ATC.C; categoria = categoria_c; }
        else if(panel_activo == 3)  { atc =  Definiciones.ATC.D; categoria = categoria_d; }
        else if(panel_activo == 4)  { atc =  Definiciones.ATC.G; categoria = categoria_g; }
        else if(panel_activo == 5)  { atc =  Definiciones.ATC.H; categoria = categoria_h; }
        else if(panel_activo == 6)  { atc =  Definiciones.ATC.J; categoria = categoria_j; }
        else if(panel_activo == 7)  { atc =  Definiciones.ATC.L; categoria = categoria_l; }
        else if(panel_activo == 8)  { atc =  Definiciones.ATC.M; categoria = categoria_m; }
        else if(panel_activo == 9)  { atc =  Definiciones.ATC.N; categoria = categoria_n; }
        else if(panel_activo == 10) { atc =  Definiciones.ATC.P; categoria = categoria_p; }
        else if(panel_activo == 11) { atc =  Definiciones.ATC.R; categoria = categoria_r; }
        else if(panel_activo == 12) { atc =  Definiciones.ATC.S; categoria = categoria_s; }
        else if(panel_activo == 13) { atc =  Definiciones.ATC.V; categoria = categoria_v; }

        if(atc != null) {
            for(Medicamento med:_l_medicamentos)
                if(med.getCategoriaMedicamento() == atc) l_medicamentos_categoria.add(med);
            int fila = categoria.getSelectedRow();
            if(fila >= 0) return l_medicamentos_categoria.get(fila);
        }
        return null;
    }

    private void moverPanel(String move) {
        JTable categoria = null;
        int panel_activo = categorias.getSelectedIndex();
        Integer fila = null;
        if(panel_activo == 0)       categoria = categoria_a;
        else if(panel_activo == 1)  categoria = categoria_b;
        else if(panel_activo == 2)  categoria = categoria_c;
        else if(panel_activo == 3)  categoria = categoria_d;
        else if(panel_activo == 4)  categoria = categoria_g;
        else if(panel_activo == 5)  categoria = categoria_h;
        else if(panel_activo == 6)  categoria = categoria_j;
        else if(panel_activo == 7)  categoria = categoria_l;
        else if(panel_activo == 8)  categoria = categoria_m;
        else if(panel_activo == 9)  categoria = categoria_n;
        else if(panel_activo == 10) categoria = categoria_p;
        else if(panel_activo == 11) categoria = categoria_r;
        else if(panel_activo == 12) categoria = categoria_s;
        else if(panel_activo == 13) categoria = categoria_v;

        if(move.equals("subir")){
            if(categoria != null) {
                fila = categoria.getSelectedRow() + 1;
                if (fila == categoria.getRowCount()) fila = 0;
            }
        } else {
            if(categoria != null) {
                fila = categoria.getSelectedRow() - 1;
                if (fila < 0) fila = categoria.getRowCount()-1;
            }
        }
        if(fila != null) categoria.setRowSelectionInterval(fila, fila);
        else categoria.setRowSelectionInterval(0,0);
    }
    private void limpiarTabla(JTable categoria) {
        while(((DefaultTableModel)categoria.getModel()).getRowCount()>0)
            ((DefaultTableModel)categoria.getModel()).removeRow(0);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jButton1 = new javax.swing.JButton();
        categorias = new javax.swing.JTabbedPane();
        jPanel1 = new javax.swing.JPanel();
        jScrollPane15 = new javax.swing.JScrollPane();
        categoria_a = new javax.swing.JTable();
        jPanel2 = new javax.swing.JPanel();
        jScrollPane16 = new javax.swing.JScrollPane();
        categoria_b = new javax.swing.JTable();
        jPanel3 = new javax.swing.JPanel();
        jScrollPane17 = new javax.swing.JScrollPane();
        categoria_c = new javax.swing.JTable();
        jPanel4 = new javax.swing.JPanel();
        jScrollPane18 = new javax.swing.JScrollPane();
        categoria_d = new javax.swing.JTable();
        jPanel5 = new javax.swing.JPanel();
        jScrollPane19 = new javax.swing.JScrollPane();
        categoria_g = new javax.swing.JTable();
        jPanel6 = new javax.swing.JPanel();
        jScrollPane20 = new javax.swing.JScrollPane();
        categoria_h = new javax.swing.JTable();
        jPanel7 = new javax.swing.JPanel();
        jScrollPane21 = new javax.swing.JScrollPane();
        categoria_j = new javax.swing.JTable();
        jPanel8 = new javax.swing.JPanel();
        jScrollPane22 = new javax.swing.JScrollPane();
        categoria_l = new javax.swing.JTable();
        jPanel9 = new javax.swing.JPanel();
        jScrollPane23 = new javax.swing.JScrollPane();
        categoria_m = new javax.swing.JTable();
        jPanel10 = new javax.swing.JPanel();
        jScrollPane24 = new javax.swing.JScrollPane();
        categoria_n = new javax.swing.JTable();
        jPanel11 = new javax.swing.JPanel();
        jScrollPane25 = new javax.swing.JScrollPane();
        categoria_p = new javax.swing.JTable();
        jPanel12 = new javax.swing.JPanel();
        jScrollPane26 = new javax.swing.JScrollPane();
        categoria_r = new javax.swing.JTable();
        jPanel13 = new javax.swing.JPanel();
        jScrollPane27 = new javax.swing.JScrollPane();
        categoria_s = new javax.swing.JTable();
        jPanel14 = new javax.swing.JPanel();
        jScrollPane28 = new javax.swing.JScrollPane();
        categoria_v = new javax.swing.JTable();
        jButton2 = new javax.swing.JButton();
        jButton3 = new javax.swing.JButton();
        jButton4 = new javax.swing.JButton();

        setFont(new java.awt.Font("Tahoma", 0, 18));
        setPreferredSize(new java.awt.Dimension(780, 470));

        javax.swing.ActionMap actionMap = org.jdesktop.application.Application.getInstance().getContext().getActionMap(seleccionarMedicamento.class, this);
        jButton1.setAction(actionMap.get("aceptar")); // NOI18N
        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance().getContext().getResourceMap(seleccionarMedicamento.class);
        jButton1.setIcon(resourceMap.getIcon("jButton1.icon")); // NOI18N
        jButton1.setLabel(resourceMap.getString("jButton2.label")); // NOI18N
        jButton1.setName("jButton1"); // NOI18N
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        categorias.setFont(new java.awt.Font("Tahoma", 0, 18));
        categorias.setName("categorias"); // NOI18N
        categorias.setPreferredSize(new java.awt.Dimension(756, 364));

        jPanel1.setFont(new java.awt.Font("Tahoma", 0, 18));
        jPanel1.setName("jPanel1"); // NOI18N
        jPanel1.setPreferredSize(new java.awt.Dimension(756, 364));

        jScrollPane15.setName("jScrollPane15"); // NOI18N

        categoria_a.setFont(new java.awt.Font("Tahoma", 0, 18));
        categoria_a.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "Nombre", "DCI o Marca", "Via de administración"
            }
        ) {
            boolean[] canEdit = new boolean [] {
                false, false, false
            };

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        categoria_a.setName("categoria_a"); // NOI18N
        jScrollPane15.setViewportView(categoria_a);

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane15, javax.swing.GroupLayout.DEFAULT_SIZE, 751, Short.MAX_VALUE)
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane15, javax.swing.GroupLayout.DEFAULT_SIZE, 319, Short.MAX_VALUE)
        );

        categorias.addTab("Categoría A", jPanel1);

        jPanel2.setName("jPanel2"); // NOI18N
        jPanel2.setPreferredSize(new java.awt.Dimension(756, 364));

        jScrollPane16.setName("jScrollPane16"); // NOI18N

        categoria_b.setFont(new java.awt.Font("Tahoma", 0, 18));
        categoria_b.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "Nombre", "DCI o Marca", "Via de administración"
            }
        ) {
            boolean[] canEdit = new boolean [] {
                false, false, false
            };

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        categoria_b.setName("categoria_b"); // NOI18N
        jScrollPane16.setViewportView(categoria_b);

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane16, javax.swing.GroupLayout.DEFAULT_SIZE, 751, Short.MAX_VALUE)
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane16, javax.swing.GroupLayout.DEFAULT_SIZE, 319, Short.MAX_VALUE)
        );

        categorias.addTab("Categoría B", jPanel2);

        jPanel3.setName("jPanel3"); // NOI18N
        jPanel3.setPreferredSize(new java.awt.Dimension(756, 364));

        jScrollPane17.setName("jScrollPane17"); // NOI18N

        categoria_c.setFont(new java.awt.Font("Tahoma", 0, 18));
        categoria_c.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "Nombre", "DCI o Marca", "Via de administración"
            }
        ) {
            boolean[] canEdit = new boolean [] {
                false, false, false
            };

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        categoria_c.setName("categoria_c"); // NOI18N
        jScrollPane17.setViewportView(categoria_c);

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane17, javax.swing.GroupLayout.DEFAULT_SIZE, 751, Short.MAX_VALUE)
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane17, javax.swing.GroupLayout.DEFAULT_SIZE, 319, Short.MAX_VALUE)
        );

        categorias.addTab("Categoría D", jPanel3);

        jPanel4.setName("jPanel4"); // NOI18N
        jPanel4.setPreferredSize(new java.awt.Dimension(756, 364));

        jScrollPane18.setName("jScrollPane18"); // NOI18N

        categoria_d.setFont(new java.awt.Font("Tahoma", 0, 18));
        categoria_d.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "Nombre", "DCI o Marca", "Via de administración"
            }
        ) {
            boolean[] canEdit = new boolean [] {
                false, false, false
            };

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        categoria_d.setName("categoria_d"); // NOI18N
        jScrollPane18.setViewportView(categoria_d);

        javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
        jPanel4.setLayout(jPanel4Layout);
        jPanel4Layout.setHorizontalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane18, javax.swing.GroupLayout.DEFAULT_SIZE, 751, Short.MAX_VALUE)
        );
        jPanel4Layout.setVerticalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane18, javax.swing.GroupLayout.DEFAULT_SIZE, 319, Short.MAX_VALUE)
        );

        categorias.addTab("Categoría D", jPanel4);

        jPanel5.setName("jPanel5"); // NOI18N
        jPanel5.setPreferredSize(new java.awt.Dimension(756, 364));

        jScrollPane19.setName("jScrollPane19"); // NOI18N

        categoria_g.setFont(new java.awt.Font("Tahoma", 0, 18));
        categoria_g.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "Nombre", "DCI o Marca", "Via de administración"
            }
        ) {
            boolean[] canEdit = new boolean [] {
                false, false, false
            };

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        categoria_g.setName("categoria_g"); // NOI18N
        jScrollPane19.setViewportView(categoria_g);

        javax.swing.GroupLayout jPanel5Layout = new javax.swing.GroupLayout(jPanel5);
        jPanel5.setLayout(jPanel5Layout);
        jPanel5Layout.setHorizontalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane19, javax.swing.GroupLayout.DEFAULT_SIZE, 751, Short.MAX_VALUE)
        );
        jPanel5Layout.setVerticalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane19, javax.swing.GroupLayout.DEFAULT_SIZE, 319, Short.MAX_VALUE)
        );

        categorias.addTab("Categoría G", jPanel5);

        jPanel6.setName("jPanel6"); // NOI18N
        jPanel6.setPreferredSize(new java.awt.Dimension(756, 364));

        jScrollPane20.setName("jScrollPane20"); // NOI18N

        categoria_h.setFont(new java.awt.Font("Tahoma", 0, 18));
        categoria_h.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "Nombre", "DCI o Marca", "Via de administración"
            }
        ) {
            boolean[] canEdit = new boolean [] {
                false, false, false
            };

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        categoria_h.setName("categoria_h"); // NOI18N
        jScrollPane20.setViewportView(categoria_h);

        javax.swing.GroupLayout jPanel6Layout = new javax.swing.GroupLayout(jPanel6);
        jPanel6.setLayout(jPanel6Layout);
        jPanel6Layout.setHorizontalGroup(
            jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane20, javax.swing.GroupLayout.DEFAULT_SIZE, 751, Short.MAX_VALUE)
        );
        jPanel6Layout.setVerticalGroup(
            jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane20, javax.swing.GroupLayout.DEFAULT_SIZE, 319, Short.MAX_VALUE)
        );

        categorias.addTab("Categoría H", jPanel6);

        jPanel7.setName("jPanel7"); // NOI18N
        jPanel7.setPreferredSize(new java.awt.Dimension(756, 364));

        jScrollPane21.setName("jScrollPane21"); // NOI18N

        categoria_j.setFont(new java.awt.Font("Tahoma", 0, 18));
        categoria_j.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "Nombre", "DCI o Marca", "Via de administración"
            }
        ) {
            boolean[] canEdit = new boolean [] {
                false, false, false
            };

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        categoria_j.setName("categoria_j"); // NOI18N
        jScrollPane21.setViewportView(categoria_j);

        javax.swing.GroupLayout jPanel7Layout = new javax.swing.GroupLayout(jPanel7);
        jPanel7.setLayout(jPanel7Layout);
        jPanel7Layout.setHorizontalGroup(
            jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane21, javax.swing.GroupLayout.DEFAULT_SIZE, 751, Short.MAX_VALUE)
        );
        jPanel7Layout.setVerticalGroup(
            jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane21, javax.swing.GroupLayout.DEFAULT_SIZE, 319, Short.MAX_VALUE)
        );

        categorias.addTab("Categoría J", jPanel7);

        jPanel8.setName("jPanel8"); // NOI18N
        jPanel8.setPreferredSize(new java.awt.Dimension(756, 364));

        jScrollPane22.setName("jScrollPane22"); // NOI18N

        categoria_l.setFont(new java.awt.Font("Tahoma", 0, 18));
        categoria_l.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "Nombre", "DCI o Marca", "Via de administración"
            }
        ) {
            boolean[] canEdit = new boolean [] {
                false, false, false
            };

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        categoria_l.setName("categoria_l"); // NOI18N
        jScrollPane22.setViewportView(categoria_l);

        javax.swing.GroupLayout jPanel8Layout = new javax.swing.GroupLayout(jPanel8);
        jPanel8.setLayout(jPanel8Layout);
        jPanel8Layout.setHorizontalGroup(
            jPanel8Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane22, javax.swing.GroupLayout.DEFAULT_SIZE, 751, Short.MAX_VALUE)
        );
        jPanel8Layout.setVerticalGroup(
            jPanel8Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane22, javax.swing.GroupLayout.DEFAULT_SIZE, 319, Short.MAX_VALUE)
        );

        categorias.addTab("Categoría L", jPanel8);

        jPanel9.setName("jPanel9"); // NOI18N
        jPanel9.setPreferredSize(new java.awt.Dimension(756, 364));

        jScrollPane23.setName("jScrollPane23"); // NOI18N

        categoria_m.setFont(new java.awt.Font("Tahoma", 0, 18));
        categoria_m.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "Nombre", "DCI o Marca", "Via de administración"
            }
        ) {
            boolean[] canEdit = new boolean [] {
                false, false, false
            };

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        categoria_m.setName("categoria_m"); // NOI18N
        jScrollPane23.setViewportView(categoria_m);

        javax.swing.GroupLayout jPanel9Layout = new javax.swing.GroupLayout(jPanel9);
        jPanel9.setLayout(jPanel9Layout);
        jPanel9Layout.setHorizontalGroup(
            jPanel9Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane23, javax.swing.GroupLayout.DEFAULT_SIZE, 751, Short.MAX_VALUE)
        );
        jPanel9Layout.setVerticalGroup(
            jPanel9Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane23, javax.swing.GroupLayout.DEFAULT_SIZE, 319, Short.MAX_VALUE)
        );

        categorias.addTab("Categoría M", jPanel9);

        jPanel10.setName("jPanel10"); // NOI18N
        jPanel10.setPreferredSize(new java.awt.Dimension(756, 364));

        jScrollPane24.setName("jScrollPane24"); // NOI18N

        categoria_n.setFont(new java.awt.Font("Tahoma", 0, 18));
        categoria_n.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "Nombre", "DCI o Marca", "Via de administración"
            }
        ) {
            boolean[] canEdit = new boolean [] {
                false, false, false
            };

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        categoria_n.setName("categoria_n"); // NOI18N
        jScrollPane24.setViewportView(categoria_n);

        javax.swing.GroupLayout jPanel10Layout = new javax.swing.GroupLayout(jPanel10);
        jPanel10.setLayout(jPanel10Layout);
        jPanel10Layout.setHorizontalGroup(
            jPanel10Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane24, javax.swing.GroupLayout.DEFAULT_SIZE, 751, Short.MAX_VALUE)
        );
        jPanel10Layout.setVerticalGroup(
            jPanel10Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane24, javax.swing.GroupLayout.DEFAULT_SIZE, 319, Short.MAX_VALUE)
        );

        categorias.addTab("Categoría N", jPanel10);

        jPanel11.setName("jPanel11"); // NOI18N
        jPanel11.setPreferredSize(new java.awt.Dimension(756, 364));

        jScrollPane25.setName("jScrollPane25"); // NOI18N

        categoria_p.setFont(new java.awt.Font("Tahoma", 0, 18));
        categoria_p.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "Nombre", "DCI o Marca", "Via de administración"
            }
        ) {
            boolean[] canEdit = new boolean [] {
                false, false, false
            };

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        categoria_p.setName("categoria_p"); // NOI18N
        jScrollPane25.setViewportView(categoria_p);

        javax.swing.GroupLayout jPanel11Layout = new javax.swing.GroupLayout(jPanel11);
        jPanel11.setLayout(jPanel11Layout);
        jPanel11Layout.setHorizontalGroup(
            jPanel11Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane25, javax.swing.GroupLayout.DEFAULT_SIZE, 751, Short.MAX_VALUE)
        );
        jPanel11Layout.setVerticalGroup(
            jPanel11Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane25, javax.swing.GroupLayout.DEFAULT_SIZE, 319, Short.MAX_VALUE)
        );

        categorias.addTab("Categoría P", jPanel11);

        jPanel12.setName("jPanel12"); // NOI18N
        jPanel12.setPreferredSize(new java.awt.Dimension(756, 364));

        jScrollPane26.setName("jScrollPane26"); // NOI18N

        categoria_r.setFont(new java.awt.Font("Tahoma", 0, 18));
        categoria_r.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "Nombre", "DCI o Marca", "Via de administración"
            }
        ) {
            boolean[] canEdit = new boolean [] {
                false, false, false
            };

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        categoria_r.setName("categoria_r"); // NOI18N
        jScrollPane26.setViewportView(categoria_r);

        javax.swing.GroupLayout jPanel12Layout = new javax.swing.GroupLayout(jPanel12);
        jPanel12.setLayout(jPanel12Layout);
        jPanel12Layout.setHorizontalGroup(
            jPanel12Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane26, javax.swing.GroupLayout.DEFAULT_SIZE, 751, Short.MAX_VALUE)
        );
        jPanel12Layout.setVerticalGroup(
            jPanel12Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane26, javax.swing.GroupLayout.DEFAULT_SIZE, 319, Short.MAX_VALUE)
        );

        categorias.addTab("Categoría R", jPanel12);

        jPanel13.setName("jPanel13"); // NOI18N
        jPanel13.setPreferredSize(new java.awt.Dimension(756, 364));

        jScrollPane27.setName("jScrollPane27"); // NOI18N

        categoria_s.setFont(new java.awt.Font("Tahoma", 0, 18));
        categoria_s.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "Nombre", "DCI o Marca", "Via de administración"
            }
        ) {
            boolean[] canEdit = new boolean [] {
                false, false, false
            };

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        categoria_s.setName("categoria_s"); // NOI18N
        jScrollPane27.setViewportView(categoria_s);

        javax.swing.GroupLayout jPanel13Layout = new javax.swing.GroupLayout(jPanel13);
        jPanel13.setLayout(jPanel13Layout);
        jPanel13Layout.setHorizontalGroup(
            jPanel13Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane27, javax.swing.GroupLayout.DEFAULT_SIZE, 751, Short.MAX_VALUE)
        );
        jPanel13Layout.setVerticalGroup(
            jPanel13Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane27, javax.swing.GroupLayout.DEFAULT_SIZE, 319, Short.MAX_VALUE)
        );

        categorias.addTab("Categoría S", jPanel13);

        jPanel14.setName("jPanel14"); // NOI18N
        jPanel14.setPreferredSize(new java.awt.Dimension(756, 364));

        jScrollPane28.setName("jScrollPane28"); // NOI18N

        categoria_v.setFont(new java.awt.Font("Tahoma", 0, 18));
        categoria_v.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "Nombre", "DCI o Marca", "Via de administración"
            }
        ) {
            boolean[] canEdit = new boolean [] {
                false, false, false
            };

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        categoria_v.setName("categoria_v"); // NOI18N
        jScrollPane28.setViewportView(categoria_v);

        javax.swing.GroupLayout jPanel14Layout = new javax.swing.GroupLayout(jPanel14);
        jPanel14.setLayout(jPanel14Layout);
        jPanel14Layout.setHorizontalGroup(
            jPanel14Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane28, javax.swing.GroupLayout.DEFAULT_SIZE, 751, Short.MAX_VALUE)
        );
        jPanel14Layout.setVerticalGroup(
            jPanel14Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane28, javax.swing.GroupLayout.DEFAULT_SIZE, 319, Short.MAX_VALUE)
        );

        categorias.addTab("Categoría V", jPanel14);

        jButton2.setAction(actionMap.get("cancelar")); // NOI18N
        jButton2.setIcon(resourceMap.getIcon("jButton2.icon")); // NOI18N
        jButton2.setLabel(resourceMap.getString("jButton2.label")); // NOI18N
        jButton2.setName("jButton2"); // NOI18N
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });

        jButton3.setAction(actionMap.get("bajar")); // NOI18N
        jButton3.setFont(resourceMap.getFont("jButton3.font")); // NOI18N
        jButton3.setIcon(resourceMap.getIcon("jButton3.icon")); // NOI18N
        jButton3.setText("Subir");
        jButton3.setToolTipText("");
        jButton3.setLabel(resourceMap.getString("jButton3.label")); // NOI18N
        jButton3.setName("jButton3"); // NOI18N

        jButton4.setAction(actionMap.get("subir")); // NOI18N
        jButton4.setFont(new java.awt.Font("Tahoma", 0, 18));
        jButton4.setIcon(resourceMap.getIcon("jButton4.icon")); // NOI18N
        jButton4.setText("Bajar");
        jButton4.setToolTipText("");
        jButton4.setHorizontalTextPosition(javax.swing.SwingConstants.LEFT);
        jButton4.setLabel(resourceMap.getString("jButton4.label")); // NOI18N
        jButton4.setName("jButton4"); // NOI18N

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(categorias, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 756, Short.MAX_VALUE)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jButton3)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jButton4)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 255, Short.MAX_VALUE)
                        .addComponent(jButton2)
                        .addGap(18, 18, 18)
                        .addComponent(jButton1)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(categorias, javax.swing.GroupLayout.DEFAULT_SIZE, 379, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addComponent(jButton1)
                        .addComponent(jButton2))
                    .addComponent(jButton3)
                    .addComponent(jButton4))
                .addContainerGap())
        );
    }// </editor-fold>//GEN-END:initComponents
    @Action
    public void subir() {
        moverPanel("subir");
    }
    @Action
    public void bajar() {
        moverPanel("bajar");
    }
    @Action
    public void cancelar() throws NoSuchAlgorithmException, IOException, ClassNotFoundException, SQLException {
        app.volver(_anterior);
    }
    @Action
    public void aceptar() throws SQLException, IOException, ClassNotFoundException, ParseException {
        Medicamento med = objetoFila(categorias.getSelectedIndex());
        if(med == null) app.abrirMensajeError("No seleccionó ningún medicamento del listado.", Interfaces.SELECCIONAR_MEDICAMENTO);
        else app.abrirOpcionesReceta(med.getIdMedicamento(),Interfaces.SELECCIONAR_MEDICAMENTO);
    }

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jButton1ActionPerformed

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jButton2ActionPerformed


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JTable categoria_a;
    private javax.swing.JTable categoria_b;
    private javax.swing.JTable categoria_c;
    private javax.swing.JTable categoria_d;
    private javax.swing.JTable categoria_g;
    private javax.swing.JTable categoria_h;
    private javax.swing.JTable categoria_j;
    private javax.swing.JTable categoria_l;
    private javax.swing.JTable categoria_m;
    private javax.swing.JTable categoria_n;
    private javax.swing.JTable categoria_p;
    private javax.swing.JTable categoria_r;
    private javax.swing.JTable categoria_s;
    private javax.swing.JTable categoria_v;
    private javax.swing.JTabbedPane categorias;
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JButton jButton3;
    private javax.swing.JButton jButton4;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel10;
    private javax.swing.JPanel jPanel11;
    private javax.swing.JPanel jPanel12;
    private javax.swing.JPanel jPanel13;
    private javax.swing.JPanel jPanel14;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JPanel jPanel5;
    private javax.swing.JPanel jPanel6;
    private javax.swing.JPanel jPanel7;
    private javax.swing.JPanel jPanel8;
    private javax.swing.JPanel jPanel9;
    private javax.swing.JScrollPane jScrollPane15;
    private javax.swing.JScrollPane jScrollPane16;
    private javax.swing.JScrollPane jScrollPane17;
    private javax.swing.JScrollPane jScrollPane18;
    private javax.swing.JScrollPane jScrollPane19;
    private javax.swing.JScrollPane jScrollPane20;
    private javax.swing.JScrollPane jScrollPane21;
    private javax.swing.JScrollPane jScrollPane22;
    private javax.swing.JScrollPane jScrollPane23;
    private javax.swing.JScrollPane jScrollPane24;
    private javax.swing.JScrollPane jScrollPane25;
    private javax.swing.JScrollPane jScrollPane26;
    private javax.swing.JScrollPane jScrollPane27;
    private javax.swing.JScrollPane jScrollPane28;
    // End of variables declaration//GEN-END:variables

}
